package com.jit.BluetoothKey.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.jit.BluetoothKey.R;
import com.jit.BluetoothKey.activity.base.BaseActivity;
import com.jit.BluetoothKey.utils.SharedPreferencesUtil;
import com.jit.BluetoothKey.utils.ToastUtils;
import com.jit.BluetoothKey.utils.UserFiled;

public class PingCodeInsertActivity extends BaseActivity implements View.OnClickListener {

    private EditText pingCode1;
    private EditText pingCode2;
    private Button ensure;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: 2018/3/2   如果不是第一登录 直接跳转到主页面
//        if (!SharedPreferencesUtil.getString(this,UserFiled.SK).equals("")){
//            startActivity(new Intent(this,MainActivity.class));
//        }
        setContentView(R.layout.activity_ping_code_insert);
    }

    @Override
    protected void initView() {
        super.initView();
        pingCode1 = (EditText) findViewById(R.id.ping_code_code1_edittext);
        pingCode2 = (EditText) findViewById(R.id.ping_code_code2_edittext);
        ensure = (Button) findViewById(R.id.ping_code_ensure_button);
    }

    @Override
    protected void initListner() {
        super.initListner();
        ensure.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ping_code_ensure_button:
                if (pingCode1.getText().toString().equals(pingCode2.getText().toString())&&!pingCode1.getText().toString().equals("")){
                    // TODO: 2018/2/27   存储SK值
                    SharedPreferencesUtil.setString(this, UserFiled.SK,pingCode1.getText().toString());
                    startActivity(new Intent(this,MainActivity.class));
                    finish();
                }else {
                    ToastUtils.showToast(this,"请保持注册码一致,且不为空");
                }
                break;
        }
    }
}
